package it.polimi.traveldream.beans;

import it.polimi.traveldream.dto.AccomodationDTO;

import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;

@ManagedBean(name = "accomodationDialogBean")
@ViewScoped
public class AccomodationDialogBean {

	private String city;

	private Integer selected;

	public AccomodationDialogBean() {
	}

	@PostConstruct
	public void init() {
		Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
				.getRequestParameterMap();

		this.city = params.get("city");

		String selected = params.get("selected");
		if (selected != null && !selected.isEmpty()) {
			this.selected = Integer.valueOf(selected);
		}
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public Integer getSelected() {
		return this.selected;
	}

	public void setSelected(Integer selected) {
		this.selected = selected;
	}

	public String select(AccomodationDTO accomodation) {
		RequestContext.getCurrentInstance().closeDialog(accomodation);
		return null;
	}
}
